package 并查集;

import org.junit.Test;
import 并查集.模板.ConnectFind;

import java.util.HashSet;
import java.util.Set;

import static MyUtils.MHUtils.*;
import static MyUtils.MHMoban.*;

/*
    每个节点只处理自己（单cur思想）
    做完题一定写入表格
*/
public class 等式方程是否全部满足_990 {
    @Test
    public void test() {
        String[] a = {"a==b","b==c","a==c"};
        System.out.println(equationsPossible(a));
    }

    //字符转数字,省了大麻烦了！！
    ConnectFind cf = new ConnectFind(26);
    public boolean equationsPossible(String[] ss) {
        //连‘==’的
        for (String s : ss) {
            if(s.substring(1,s.length()-1).equals("==")) {
                int fir = s.charAt(0) - 'a';
                int sec = s.charAt(s.length()-1)-'a';
                System.out.println(fir+" "+sec);
                cf.connect(fir, sec);
            }
        }
        //不同根(之前没有单向相连)的才可以!=
        //"c==c","a==b","b==d","x!=z" -> true
        for (String s : ss) {
            if(s.substring(1,s.length()-1).equals("!=")) {
                int fir = s.charAt(0) - 'a';
                int sec = s.charAt(s.length() - 1) - 'a';
                if (cf.find_returnRot(fir) == cf.find_returnRot(sec)) {
                    return false;
                }
            }
        }
        return true;
    }
}
